<template>
  <footer class="footer">
    <!-- This should be `0 items left` by default -->
    <span class="todo-count"
      ><strong>{{ surplus }}</strong> item left</span
    >
    <!-- Remove this if you don't implement routing -->
    <ul class="filters">
      <li>
        <a
          href="#/"
          :class="{ selected: type === 'all' }"
          @click.prevent="filter('all')"
          >All</a
        >
      </li>
      <li>
        <a
          href="#/active"
          :class="{ selected: type === 'active' }"
          @click.prevent="filter('active')"
          >Active</a
        >
      </li>
      <li>
        <a
          href="#/completed"
          :class="{ selected: type === 'completed' }"
          @click.prevent="filter('completed')"
          >Completed</a
        >
      </li>
    </ul>
    <!-- Hidden if no completed items are left ↓ -->
    <button
      class="clear-completed"
      v-show="surplus !== list.length"
      @click="clear"
    >
      Clear completed
    </button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
    type: {
      type: String,
      default: 'all',
    },
  },
  computed: {
    surplus() {
      return this.list.filter(item => item.isDone === false).length
    },
  },
  methods: {
    clear() {
      this.$emit('clear')
    },
    filter(type) {
      this.$emit('filter', type)
    },
  },
}
</script>

<style></style>
